package org.omixed.flex;

import java.net.InetAddress;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

import org.apache.log4j.PropertyConfigurator;

public class ShellAntTask extends Task 
{
	private String command;
	
	public void execute() throws BuildException 
	{
		PropertyConfigurator.configure("log4j.properties");
		
		try
		{
			InetAddress addr = InetAddress.getByName("localhost");
			ShellClient client = new ShellClient(addr, 53000, command);
			String result = client.send();
			System.out.println(result);
			client.close();
		} catch (java.net.UnknownHostException uhe)
		{
			throw new BuildException(uhe.getMessage());
		} catch (java.io.IOException ioe)
		{
			throw new BuildException(ioe.getMessage());
		} catch (ShellException se)
		{
			throw new BuildException(se.getMessage());
		}
	}
	
	public void setCommand(String command) {
		this.command = command;
	}
}